clear;clc;close all;

function_num = 'F7';    %使用的目标函数名

[lb,ub,dim,fobj] = CEC2005(function_num);   %去测试集中取出目标函数

pop_num = 100;  %种群的数量
max_iter= 20;  %最大迭代次数

%算法比较

compare_time = [];  %耗费时间
names = [];
compare_fival= [];  %最终目标值
compare_curve= [];  %算法的过程比较（收敛曲线）

%%  标准粒子群
[basePSO_curve,basePSO_pos,basePSO_fval] = basePSO(fobj,pop_num,max_iter,dim);
names = [names;"basePSO"];
compare_curve = [compare_curve;basePSO_curve];

%%  随机权重惯性因子粒子群
[RandWPSO_curve,RandWPSO_pos,RandWPSO_fval] = RandWPSO(fobj,pop_num,max_iter,dim);
names = [names;"RandWPSO"];
compare_curve = [compare_curve;RandWPSO_curve];

%%  线性递减惯性因子粒子群
[LinPSO_curve,LinPSO_pos,LinPSO_fval] = LinPSO(fobj,pop_num,max_iter,dim);
names = [names;"LinPSO"];
compare_curve = [compare_curve;LinPSO_curve];

%%  混沌局部搜索粒子群
[ChaosPSO_curve,ChaosPSO_pos,ChaosPSO_fval] = ChaosPSO(fobj,pop_num,max_iter,lb,ub,dim);
names = [names;"ChaosPSO"];
compare_curve = [compare_curve;ChaosPSO_curve];

%%  自适应权重因子粒子群
[SAPSO_curve,SAPSO_pos,SAPSO_fval] = SAPSO(fobj,pop_num,max_iter,dim);
names = [names;"SAPSO"];
compare_curve = [compare_curve;SAPSO_curve];

%%  学习因子同步变换
[LnCPSO_curve,LnCPSO_pos,LnCPSO_fval] = LnCPSO(fobj,pop_num,max_iter,dim);
names = [names;"LnCPSO"];
compare_curve = [compare_curve;LnCPSO_curve];
%% 二阶粒子群
[SecPSO_curve,SecPSO_pos,SecPSO_fval] = SecPSO(fobj,pop_num,max_iter,dim);
names = [names;"SecPSO"];
compare_curve = [compare_curve;SecPSO_curve];
%%  异步学习因子变换
[AsyLnCPSO_curve,AsyLnCPSO_pos,AsyLnCPSO_fval] = AsyLnCPSO(fobj,pop_num,max_iter,dim);
names = [names;"AsyLnCPSO"];
compare_curve = [compare_curve;AsyLnCPSO_curve];
%%  带繁殖机制的粒子群
[BreedPSO_curve,BreedPSO_pos,BreedPSO_fval] = BreedPSO(fobj,pop_num,max_iter,dim);
names = [names;"BreedPSO"];
compare_curve = [compare_curve;BreedPSO_curve];


%%  最佳适应度值
display(basePSO_fval);  %搜寻出来的最优解的函数值
display(RandWPSO_fval);
display(LinPSO_fval);
display(ChaosPSO_fval);
display(SAPSO_fval);
display(LnCPSO_fval);
display(SecPSO_fval);
display(AsyLnCPSO_fval);
display(BreedPSO_fval);
%% -------------------收敛曲线对比-------------------------

load("color_list.mat");
%color_all=color_list(randperm(length(color_list)),:);
figure('Name','收敛曲线');

rows = size(compare_curve);
for i = 1 : rows(1)
     plot(compare_curve(i,:),'Color',color_list(i,:),'LineWidth',2);
     hold on;
end
ylabel('目标函数值');
xlabel('迭代次数');
grid on;
box on;
legend(names);

%% -------------------最佳目标对比-------------------------



